﻿@{
    Layout = "~/Views/Shared/_LayoutTree.cshtml";
    ViewBag.LeftTitle = "日期类型";
}
@section Left{
    @(Html.nbTree(s =>
    {
        s.ID("Tree");
        s.Action("Tree");
        s.layoutH(30);
        s.Width(200);
        s.Grid("date");
        s.Sync(false);
    }))
}
@section Right{
    @(Html.nbGridFor<DishRangeView>(s =>
    {
        s.layoutW(208);
        s.layoutH(114);
        s.Columns(c =>
        {
            c.Bind(m => m.Id).IsKey();
            c.BindDateTime(m => m.Date).Title("日期").AsSearch();
            c.Bind(m => m.MealType).Title("餐单分类").Width(50).AsSearch();
            c.BindEnum(m => m.MainMaterialType, "MaterialCategory").Title("主料分类").Width(50).AsSearch();
            c.BindEnum(m => m.Category, "DishType").Title("类别").Width(40).AsSearch();
            c.Bind(m => m.Name).Title("菜肴名称").Width(100).AsQuery().AsSearch().Align(GridAlign.Left);
            c.Bind(m => m.Cost).Title("成本(元)").Width(50).Align(GridAlign.Right).AsSearch();
            c.Bind(m => m.ItemDesc).Title("品名信息").Width("auto").Align(GridAlign.Left).AsQuery().AsSearch();
            c.BindDateTime(m => m.UpdateDate).Title("添加时间");
            c.BindTemplate(60).Template(Url.GridRowDeleteLink("Name"));

        });
        s.Buttons(b =>
        {
            b.BindAddButton("大锅菜").OnClick("AddBigDish");
            b.BindAddButton("商务套餐").OnClick("AddBusinessDish");
            b.BindAddButton("风味小吃").OnClick("AddFlavorDish");
            b.BindAddButton("面档浇头").OnClick("AddMealDish");
            b.BindAddButton("盖浇饭").OnClick("AddRiceDish");
            b.BindAddButton("晚餐").OnClick("AddDinnerDish");
            b.BindDeleteButton();
        });
    }))
}
@Html.Js("json2")
<script type="text/javascript">
    function AddBigDish() {
        AddDish("大锅菜");
    }

    function AddBusinessDish() {
        AddDish("商务套餐");
    }

    function AddFlavorDish() {
        AddDish("风味小吃");
    }

    function AddMealDish() {
        AddDish("面档浇头");
    }

    function AddRiceDish() {
        AddDish("盖浇饭");
    }

    function AddDinnerDish() {
        AddDish("晚餐");
    }


    function AddDish(type) {
        OpenModalDialog('@Url.Action("Lookup", "Dish")',
        {
            width: 620,
            height: 500,
            caption: "选择菜肴",
            onclose: function (dishes) {
                if (dishes) {
                    var json = { date: $("#Tree").getTCT().id, MealType: type };
                    json["dishList"] = dishes;

                    // 将数据保存到数据库中
                    ajaxTodo('@Url.Action("AddDish")', JSON.stringify(json), refreshGrid);
                }
            }
        });
    }
</script>
